import formatterTime from '../utils/formatterTime';

function ObjectClone (template, source, templateType = 'formFunction') {
  let obj = {};
  let step = template;
  for (let i in step) {
    if (!step.hasOwnProperty(i)) continue;
    switch (templateType) {
    case 'formFunction':
      if (template[i].value.constructor === Object) {
        ObjectClone(obj[i], template[i].value, source ? (source[i] || '') : '', templateType);
      } else {
        obj[i] = source ? (source[i] || '') : (step[i].value || '');
      }
      break;
    case 'Object':
      if (template[i].constructor === Object) {
        ObjectClone(obj[i], template[i], source ? (source[i] || '') : '', templateType);
      } else {
        obj[i] = source ? (source[i] || '') : (step[i] || '');
      }
      break;
    }
  }
  return obj;
}

export default option => {
  option.methods = {
    ...option.methods,
    formatterTime, // 格式化 日期
    ObjectClone, // 对象克隆
  };
};
